package com.zbf.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbf.dao.TestMapper;
import com.zbf.entity.TestUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * @author: LCG
 * @date: 2022-07-12 21:47:52
 * @description:
 **/
@Service
public class TestUserServiceImpl extends ServiceImpl<TestMapper, TestUser> implements TestUserService {

    @Autowired
    private TestMapper testMapper;


    /**
     * @author: LCG
     * @date: 2022-07-12 22:31:08
     * @description:  Wrappers条件构造起的更新
     */
    @Override
    public void testUpdate(TestUser testUser) {


        LambdaUpdateWrapper<TestUser> objectLambdaUpdateWrapper = Wrappers.lambdaUpdate();

        objectLambdaUpdateWrapper.eq(TestUser::getId,testUser.getId());
        //根据条件进行拼接
        //objectLambdaUpdateWrapper.eq(testUser.getId()!=null,TestUser::getId,testUser.getId());
        testUser.setLoginName("Login456");

        testMapper.update(testUser,objectLambdaUpdateWrapper);

    }

    @Override
    public void testQuery(TestUser testUser) {


        LambdaQueryWrapper<TestUser> mapLambdaQueryWrapper = Wrappers.<TestUser>lambdaQuery();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //查询条件为创建时间
        mapLambdaQueryWrapper.apply(testUser.getStartDate()!=null," createTime >= '"+simpleDateFormat.format(testUser.getStartDate())+"'");
        mapLambdaQueryWrapper.apply(testUser.getEndDate()!=null," createTime <= '"+simpleDateFormat.format(testUser.getEndDate())+"'");
        mapLambdaQueryWrapper.ne(TestUser::getId,testUser.getId());
        List<TestUser> testUsers = testMapper.selectList(mapLambdaQueryWrapper);
        testUsers.forEach(testUser1 -> {
            System.out.println(testUser1);
        });
        
    }


}
